000100******************************************************************
000200*PROGRAM : Change course information                             *
000300*AUTHOR  : Elijah Yang                                           *
000400******************************************************************
000500 IDENTIFICATION DIVISION.
000600 PROGRAM-ID. BLDG-C.
000700 ENVIRONMENT DIVISION.
000800     SELECT IOFILE       ASSIGN TO "BLDGMST.DAT"
000900                         ORGANIZATION  IS INDEXED
001000                         ACCESS        IS RANDOM
001100                         RECORD KEY    IS BLDG-CODE
001200                         FILE STATUS   IS WS-STAT.
001300
001400 DATA DIVISION.
001500 FILE SECTION.
001600 FD  IOFILE.
001700 01  OUT-REC.
001800     03  BLDG-CODE      PIC X(11).
001900     03  CAPACITY    PIC 9(3).
002000
002100     03  IO-CRS-A       PIC X.
002200
002300 WORKING-STORAGE SECTION.
002400 01  WS-STAT             PIC XX.
002500 01  WS-EOF              PIC X VALUE 'N'.
002600 01  WS-BLDG-CODE           PIC X(11).
002700 01  WS-CAPACITY         PIC 9(3).
002800
002900 01  WS-CRS-A            PIC X.
003000 01  WS-DATE.
003100     03  WS-YEAR         PIC 99.
003200     03  WS-MONTH        PIC 99.
003300     03  WS-DAY          PIC 99.
003400 01  WS-ERR              PIC X VALUE 'N'.
003500 01  WS-CONT             PIC X VALUE 'Y'.
       01  WS-UPDATE           PIC X VALUE 'N'.
003600
003700 SCREEN SECTION.
003800 01  INPUT-BLDG-CODE-SCRN.
003900         05  BLANK SCREEN.
004000         05  LINE 1  COL 01  VALUE "CHANGE BUILDING".
004100         05          COL 73  PIC 9(2) FROM WS-MONTH.
004200         05          COL 75  VALUE "/".
004300         05          COL 76  PIC 9(2) FROM WS-DAY.
004400         05          COL 78  VALUE "/".
004500         05          COL 79  PIC 9(2) FROM WS-YEAR.
004600         05  LINE 2  COL 34  VALUE "CHANGE BUILDING".
004700         05  LINE 5  COL 30   VALUE "BUILDING CODE".
004800         05          COL 47  PIC X(11) TO WS-BLDG-CODE.
               05          COL 60  VALUE "EX: BALDOR141A".
004900         05  LINE 11 COL 34  VALUE "(ENTER XXX TO EXIT)".
005000
005100
005200 01  INPUT-SCRN.
005300         05  BLANK SCREEN.
005400         05  LINE 1  COL 01  VALUE "BUILDING COURSE".
005500         05          COL 73  PIC 9(2) FROM WS-MONTH.
005600         05          COL 75  VALUE "/".
005700         05          COL 76  PIC 9(2) FROM WS-DAY.
005800         05          COL 78  VALUE "/".
005900         05          COL 79  PIC 9(2) FROM WS-YEAR.
006000         05  LINE 2  COL 37  VALUE "CHANGE BUILDING".
006100         05  LINE 5  COL 01  VALUE "BUILDING CODE".
006200         05          COL 17  PIC X(11) FROM BLDG-CODE.
006300         05  INPUT-CRS-NAME-SCRN.
006400             10  LINE 6  COL 1   VALUE "CAPACITY".
006500             10          COL 17  PIC 9(3) FROM CAPACITY.
006600             10          COL 50  PIC 9(3) TO WS-CAPACITY.
006700
007100         05  INPUT-CRS-A-SCRN.
007200             10  LINE 8  COL 1   VALUE "ACTIVATE (Y/N)?".
007300             10          COL 17  PIC X FROM IO-CRS-A.
007400             10          COL 50  PIC X TO WS-CRS-A.

               05  INPUT-UPDATE-SCRN.
                   10  LINE 9  COL 1   VALUE "DO YOU WANT TO UPDATE(Y/N)
      -            "?".
                   10          COL 50  PIC X TO WS-UPDATE AUTO.
007500         05  LINE 11 COL 30  VALUE "(LEAVE BLANK TO KEEP THE OLD V
007600-                "ALUE)".

           01  ERROR-SCRN.
               03  BLANK SCREEN.
               03  LINE 12 COL 32 VALUE "COULD NOT FIND THIS BUILDING".
               03  LINE 16 COL 32 VALUE "CONTINUE(Y/N)?".
               03          COL 47 PIC X TO WS-CONT AUTO.

           01  CONT-SCRN.
               03  BLANK SCREEN.
               03  LINE 12 COL 32 VALUE "DO YOU WANT TO CONTINUE?".
               03  LINE 16 COL 32 VALUE "CONTINUE(Y/N)?".
               03          COL 47 PIC X TO WS-CONT AUTO.

008200
008300 01  SUCCESS-SCRN.
008400     03  BLANK SCREEN.
008500     03  LINE 12 COL 32 VALUE "RECORD CHANGED SUCCESSFULLY".
008600     03  LINE 13 COL 32 VALUE "RECORD INFORMATION CHANGED TO:".
008700     03  LINE 14 COL 32 VALUE "BUILDING ID".
008800     03          COL 46 PIC X(11) FROM BLDG-CODE.
008900     03  LINE 15 COL 32 VALUE "CAPACITY".
009000     03          COL 46 PIC 9(3) FROM CAPACITY.
009100
009200
009300     03  LINE 17 COL 32 VALUE "ACTIVATE?".
009400     03          COL 46 PIC X FROM IO-CRS-A.
009500     03  LINE 18 COL 32 VALUE "CONTINUE(Y/N)?".
009600     03          COL 47 PIC X TO WS-CONT AUTO.
009700
009800
009900 PROCEDURE DIVISION.
010000 100-MAIN.
010100     ACCEPT WS-DATE FROM DATE
010200     OPEN I-O IOFILE.
010300
010400     MOVE SPACES TO WS-BLDG-CODE
010500     MOVE ZEROES TO WS-CAPACITY
010600
010700     MOVE SPACES TO WS-CRS-A
           MOVE SPACES TO WS-UPDATE
010800     MOVE 'Y' TO WS-CONT
010900
011000     DISPLAY INPUT-BLDG-CODE-SCRN
011100     ACCEPT INPUT-BLDG-CODE-SCRN
011200     PERFORM UNTIL WS-BLDG-CODE = 'XXX' OR WS-CONT = 'N'
011300
011400         MOVE WS-BLDG-CODE TO BLDG-CODE
011500         READ IOFILE
011600             INVALID KEY MOVE 'Y' TO WS-ERR
011700         END-READ
011800
011900         IF WS-ERR = 'Y'
012000             DISPLAY ERROR-SCRN
012100             ACCEPT ERROR-SCRN
012200         ELSE
012300             DISPLAY INPUT-SCRN
012400             ACCEPT INPUT-CRS-NAME-SCRN
012500
012600             ACCEPT INPUT-CRS-A-SCRN
012700
012800             IF NOT WS-CAPACITY = ZEROS
012900                 MOVE WS-CAPACITY    TO CAPACITY
013000             END-IF
013100
013200             IF NOT WS-CRS-A = SPACES
013300                 MOVE WS-CRS-A       TO IO-CRS-A
013400             END-IF

                   ACCEPT INPUT-UPDATE-SCRN
013500
                   IF WS-UPDATE = 'Y'
                       MOVE 'N' TO WS-ERR

                       REWRITE OUT-REC
                           INVALID KEY MOVE 'Y' TO WS-ERR
                       END-REWRITE

                       IF WS-ERR = 'Y'
                           DISPLAY ERROR-SCRN
                           ACCEPT ERROR-SCRN
                       ELSE
                           DISPLAY SUCCESS-SCRN
                           ACCEPT SUCCESS-SCRN
                       END-IF

                   ELSE
                       DISPLAY CONT-SCRN
                       ACCEPT CONT-SCRN
                   END-IF
014100
014900         END-IF

015000         IF NOT WS-CONT = 'N'
015100             DISPLAY INPUT-BLDG-CODE-SCRN
015200             MOVE SPACES TO WS-BLDG-CODE
015300             MOVE ZEROES TO WS-CAPACITY
015400
015500             MOVE SPACES TO WS-CRS-A
015600             MOVE 'N' TO WS-ERR
015700             ACCEPT INPUT-BLDG-CODE-SCRN
015800         END-IF
015900
016000     END-PERFORM
016100     CLOSE IOFILE
016200     EXIT PROGRAM.
016300
